<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            margin: 0;
        }
        
        h2 {
            text-align: center;
        }
        
        ul {
            list-style: none;
            padding: 0;
            margin: 0;
            display: flex;
            justify-content: space-around;
        }
        
        .acitve {
            color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <router-view></router-view>
    </div>
    <script src="./js/vue.js"></script>
    <script src="./js/vue-router.js"></script>
    <script>
        // 假设有一个动物园  大门 售票处 熊猫区 老虎区 猴子区 大象区
        const Zoo = {
            template: `<div>
                    <h2>动物园</h2>
                    <ul>
                        <router-link tag="li" active-class="normal" exact-active-class="acitve" to="/monkey">猴子区</router-link>
                        <router-link tag="li" active-class="normal" exact-active-class="acitve" to="/elephont">大象区</router-link>
                        <router-link tag="li" active-class="normal" exact-active-class="acitve" to="/tiger">老虎区</router-link>
                        <router-link tag="li" active-class="normal" exact-active-class="acitve" to="/panda">熊猫区</router-link>
                    </ul>
                    <router-view></router-view>
                </div>`
        }

        const Monkey = {
            template: `
                <div>
                    <img src="./imgs/monkey.webp" />
                </div>
            `
        }

        const Panda = {
            template: `
                <div>
                    <img src="./imgs/panda.webp" />
                </div>
            `
        }

        const Tiger = {
            template: `
                <div>
                    <img src="./imgs/tiger.webp" />
                    <router-link :to="{
                        name: 'detail',
                        params: {
                            type: 'tiger'
                        }
                    }">查看详细信息</router-link>
                </div>
            `,

        }

        const Elephont = {
            template: `
                <div>
                    <img src="./imgs/elephont.webp" />
                </div>
            `
        }


        const Detail = {
            template: `
                <div>
                    老虎 大型食肉类猫科动物
                </div>
            `,
            created() {
                console.log(this.$route);
            }
        }
        const routes = [{
            path: '/',
            component: Zoo,
            redirect: '/monkey',
            children: [{
                path: 'monkey',
                component: Monkey,
            }, {
                path: 'panda',
                component: Panda
            }, {
                path: 'tiger',
                component: Tiger
            }, {
                path: 'elephont',
                component: Elephont
            }]
        }, {
            path: '/detail',
            name: 'detail',
            component: Detail
        }]
        let router = new VueRouter({
            routes
        })
        Vue.component('Zoo', Zoo)
        new Vue({
            el: "#app",
            router
        })
    </script>
</body>

</html>